package com.geotmt.billingcenter.modules.hive.service.impl;

import com.geotmt.billingcenter.common.entry.ConsumeStatisEntry;
import com.geotmt.billingcenter.config.datasources.DataSourceContextHolder;
import com.geotmt.billingcenter.config.datasources.TargetDataSource;
import com.geotmt.billingcenter.modules.hive.mapper.ConsumeHiveMapper;
import com.geotmt.billingcenter.modules.hive.service.ConsumeHiveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.sql.DataSource;
import java.util.List;

/**
 * @Description hive Server
 * @Author      yanghanwei
 * @Mail        yanghanwei@geotmt.com
 * @Date        2019/3/19 10:54
 * @Version     v1
 **/
@Service
public class ConsumeHiveServiceImpl implements ConsumeHiveService {

    private static final Logger logger = LoggerFactory.getLogger(ConsumeHiveServiceImpl.class);

    @Resource
    private ConsumeHiveMapper consumeHiveMapper;

    @TargetDataSource(value = DataSourceContextHolder.HIVE)
    @Override
    public void createTest(String tableName) {
        logger.info("测试...");
        consumeHiveMapper.createTest(tableName);
    }

    @TargetDataSource(value = DataSourceContextHolder.HIVE)
    @Override
    public List<ConsumeStatisEntry> listConsume(String dayFlag) {
        logger.info("查询hive中消耗的List,dayFlag:{}",dayFlag);
        return consumeHiveMapper.listConsume(dayFlag);
    }

    @TargetDataSource(value = DataSourceContextHolder.HIVE)
    @Override
    public List<ConsumeStatisEntry> listConsume2(String startDay, String endDay) {
        logger.info("查询hive中某段时间内的消耗List,startDay:{},endDay:{}", startDay, startDay);
        return  consumeHiveMapper.listConsume2(startDay, endDay);
    }
}
